#!/bin/bash
CURRENT_USER=$(echo $USER)
if [ "$CURRENT_USER" != 'root' ]; then
    echo "Permission denied by user $CURRENT_USER. Add 'sudo' before the command."
    exit -1
fi
diskutil unmountDisk /dev/disk2
{
  sudo dd if=/Users/ddy/Downloads/5-ISO/2019-04-08-raspbian-stretch-lite.img of=/dev/rdisk2 bs=1m conv=sync;
  sleep 10;
  diskutil unmountDisk /dev/disk2
}&
{
  sleep 5
  for i in {1..10000}; do
    pid=`ps aux| grep 'dd if' | grep -v sudo | grep -v grep | awk '{print $2}'`
    if [[ "x$pid" == "x" ]]; then
      break
    fi
  	sudo kill -SIGINFO $pid
  	sleep 10
  done
}&

